﻿
@{
    ViewBag.Title = "车间仓库存";
    Layout = "~/Views/Shared/_LayoutPage.cshtml";
    var warehouses = ViewBag.Warehouses as List<IOA.MES.DataAccess.VModel.VUserWarehouse>;
}

<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-form layui-card-header layuiadmin-card-header-auto">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">车间仓库：</label>
                    <div class="layui-input-inline">
                        <select name="warehouseCode">
                            <option value="">全部仓库</option>
                            @foreach (var item in warehouses)
                            {
                                <option value="@item.WarehouseCode">@item.WarehouseName</option>
                            }
                        </select>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">分类信息：</label>
                    <div class="layui-input-inline">
                        <input type="text" name="category" class="layui-input" value="" />
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">物料信息：</label>
                    <div class="layui-input-inline">
                        <input type="text" name="product" class="layui-input" value="" />
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">批次号：</label>
                    <div class="layui-input-inline">
                        <input type="text" name="batchNo" class="layui-input" value="" />
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">库存状态：</label>
                    <div class="layui-input-inline">
                        <select name="storageStatus">
                            <option value="">全部状态</option>
                            <option value="1" selected>有库存</option>
                            <option value="0">无库存</option>
                        </select>
                    </div>
                </div>
                <div class="layui-inline">
                    <button id="btnSearch" class="layui-btn layuiadmin-btn-list" type="button" lay-submit lay-filter="submit">
                        <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                    </button>
                </div>
            </div>
        </div>
    </div>

    <div class="layui-card">
        <div class="layui-card-body">
            <table id="table" lay-filter="table"></table>
        </div>
    </div>
</div>

@section Scripts{
    <script>
        initLayui();
        function initLayui() {
            layui.use(['table', 'layer', 'laydate', 'form'], function () {
                var layer = layui.layer,
                    table = layui.table,
                    form = layui.form;

                var options = {
                    elem: '#table'
                    , url: '/Warehouse/QueryWorkshopWarehouseStorages'
                    , method: "post"
                    , where: { warehouseCode: "", category: "", product: "", batchNo: "", storageStatus: null }
                    , page: {
                        limit: 15
                        , limits: [15, 20, 25, 30, 40, 50]
                    }
                    , response: {
                        statusName: 'ErrCode'
                        , statusCode: 200
                        , msgName: 'ErrCode'
                        , countName: 'TotalCount'
                        , dataName: 'Data'
                    }
                    , cols: [[
                        { title: '序号', type: "numbers", width: 60 }
                        , {
                            title: '物料分类', width: 200, templet: function (d) {
                                return d.CategoryCode + "-" + d.CategoryName;
                            }
                        }
                        , { field: 'ProductCode', width: 200, title: '物料编码' }
                        , { field: 'ProductName', width: 200, title: '物料名称' }
                        , { field: 'PackBatchNo', title: '批次号' }
                        , { field: 'Quantity', title: '库存数量', width: 100 }
                        , {
                            title: '操作', width: 150, fixed: "right", templet: function (d) {
                                var str = '<button class="layui-btn layui-btn-sm layui-btn-normal" onclick="checkLog("' + d.ProductCode + '","' + d.BatchNo + '")"><i class="layui-icon">&#xe642;</i>出入库记录</button>';
                                return str;
                            }
                        }
                    ]]
                };
                form.on('submit(submit)', function (data) {
                    var forms = data.field;
                    console.log(forms);
                    forms.storageStatus = forms.storageStatus == "" ? null : (forms.storageStatus == "1");
                    options.where = forms;
                    queryTable();
                    return false;
                });
                queryTable();
                function queryTable() {
                    if (table.index <= 0) {
                        table.render(options);
                    } else {
                        table.reload("table", options);
                    }
                }
            });
        }

        function modifyStatus(productCode, batchNo) {

        }
    </script>
}
